package cn.admin.remoting.impl;

import cn.admin.remoting.RequestControl;

public class RequestControlImpl implements RequestControl {

    private final boolean isProtocolControl;
    private final byte protocol;
    private final boolean isTimeoutControl;
    private final long timeout;
    private final ClassLoader rspClassLoader;

    public RequestControlImpl(byte protocol) {
        this.isProtocolControl = true;
        this.protocol = protocol;
        this.isTimeoutControl = false;
        this.timeout = -1L;
        this.rspClassLoader = null;
    }

    public RequestControlImpl(long timeout) {
        this.isTimeoutControl = true;
        this.timeout = timeout;
        this.isProtocolControl = false;
        this.protocol = -1;
        this.rspClassLoader = null;
    }

    public RequestControlImpl(byte protocol,long timeout) {
        this.isProtocolControl = true;
        this.protocol = protocol;
        this.isTimeoutControl = true;
        this.timeout = timeout;
        this.rspClassLoader = null;
    }

    public RequestControlImpl(byte protocol,long timeout,ClassLoader rspClassLoader) {
        this.isProtocolControl = true;
        this.protocol = protocol;
        this.isTimeoutControl = true;
        this.timeout = timeout;
        this.rspClassLoader = rspClassLoader;
    }

    @Override
    public boolean isProtocolControl() {
        return isProtocolControl;
    }

    @Override
    public byte getProtocol() {
        if (!this.isProtocolControl) {
            throw new UnsupportedOperationException();
        }
        return this.protocol;
    }

    @Override
    public boolean isTimeoutControl() {
        return isTimeoutControl;
    }

    @Override
    public long getTimeout() {
        if (!this.isTimeoutControl) {
            throw new UnsupportedOperationException();
        }
        return timeout;
    }

    @Override
    public ClassLoader getRspClassLoader() {
        return rspClassLoader;
    }
}
